diff --git a/lang/en_utf8/forum.php b/lang/en_utf8/forum.php
index bbde533..cf7519a 100644
--- a/lang/en_utf8/forum.php
+++ b/lang/en_utf8/forum.php
@@ -25,6 +25,7 @@ $string['anonno'] = 'No, never';
 $string['anonoptional'] = 'Optional (let the user decide)';
 $string['anonyes'] = 'Yes, all posts';
 $string['anonymouspost'] = 'Post anonymously';
+$string['anonymousname'] = 'Anonymous user name';
 $string['anyfile'] = 'Any file';
 $string['attachment'] = 'Attachment';
 $string['blockafter'] = 'Post threshold for blocking';
@@ -35,6 +36,7 @@ $string['cannotviewpostyet'] = 'You cannot read other students questions in this
 $string['cannotadddiscussion'] = 'Adding discussions to this forum requires group membership.';
 $string['cannotadddiscussionall'] = 'You do not have permission to add a new discussion topic for all participants.';
 $string['cleanreadtime'] = 'Mark old posts as read hour';
+$string['configanonymousname'] = 'The user name to display on anonymous forum posts.';
 $string['configcleanreadtime'] = 'The hour of the day to clean old posts from the \'read\' table.';
 $string['configdisplaymode'] = 'The default display mode for discussions if one isn\'t set.';
 $string['configenablerssfeeds'] = 'This switch will enable the possibility of RSS feeds for all forums.  You will still need to turn feeds on manually in the settings for each forum.';
diff --git a/mod/forum/db/install.xml b/mod/forum/db/install.xml
index 9ca9957..79e6d40 100644
--- a/mod/forum/db/install.xml
+++ b/mod/forum/db/install.xml
@@ -23,7 +23,8 @@
         <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="rssarticles" NEXT="warnafter"/>
         <FIELD NAME="warnafter" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="timemodified" NEXT="blockafter"/>
         <FIELD NAME="blockafter" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="warnafter" NEXT="blockperiod"/>
-        <FIELD NAME="blockperiod" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="blockafter"/>
+        <FIELD NAME="blockperiod" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="blockafter" NEXT="anonymous"/>
+        <FIELD NAME="anonymous" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="blockperiod"/>
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
@@ -69,7 +70,8 @@
         <FIELD NAME="format" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="message" NEXT="attachment"/>
         <FIELD NAME="attachment" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="format" NEXT="totalscore"/>
         <FIELD NAME="totalscore" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="attachment" NEXT="mailnow"/>
-        <FIELD NAME="mailnow" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="totalscore"/>
+        <FIELD NAME="mailnow" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="totalscore" NEXT="anonymous"/>
+        <FIELD NAME="anonymous" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="mailnow"/>
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="discussion"/>
diff --git a/mod/forum/db/upgrade.php b/mod/forum/db/upgrade.php
index 99c8212..ea32586 100644
--- a/mod/forum/db/upgrade.php
+++ b/mod/forum/db/upgrade.php
@@ -83,6 +83,16 @@ function xmldb_forum_upgrade($oldversion=0) {
         }
     }
 
+    if ($result && $oldversion < 2007101513) {
+        $table = new XMLDBTable('forum');
+        $field = new XMLDBField('anonymous');
+        $field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'blockperiod');
+        $result = $result && add_field($table, $field);
+        $table = new XMLDBTable('forum_posts');
+        $field = new XMLDBField('anonymous');
+        $field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'mailnow');
+        $result = $result && add_field($table, $field);
+    }
 
     return $result;
 }
diff --git a/mod/forum/lib.php b/mod/forum/lib.php
index 83bb70b..dd8301f 100644
--- a/mod/forum/lib.php
+++ b/mod/forum/lib.php
@@ -441,7 +441,7 @@ function forum_cron() {
                 $posthtml = forum_make_mail_html($course, $forum, $discussion, $post, $userfrom, $userto);
 
                 $post->anonymous = $forum->anonymous == 1 ? true : ($forum->anonymous == 2 ? $post->anonymous : false);
-                $userfrom = $post->anonymous ? $CFG->anonymous_name : $userfrom;
+                $userfrom = $post->anonymous ? $CFG->forum_anonymousname : $userfrom;
 
                 // Send the post now!
 
@@ -811,7 +811,7 @@ function forum_make_mail_text($course, $forum, $discussion, $post, $userfrom, $u
     }
 
     $by = New stdClass;
-    $by->name = $post->anonymous ? $CFG->anonymous_name : fullname($userfrom, $viewfullnames);
+    $by->name = $post->anonymous ? $CFG->forum_anonymousname : fullname($userfrom, $viewfullnames);
     $by->date = userdate($post->modified, "", $userto->timezone);
 
     $strbynameondate = get_string('bynameondate', 'forum', $by);
@@ -1155,7 +1155,7 @@ function forum_print_recent_activity($course, $viewfullnames, $timestart) {
 
     foreach ($printposts as $post) {
         $subjectclass = empty($post->parent) ? ' bold' : '';
-        $fullname = $post->anonymous ? $CFG->anonymous_name : fullname($post, $viewfullnames);
+        $fullname = $post->anonymous ? $CFG->forum_anonymousname : fullname($post, $viewfullnames);
 
         echo '<li><div class="head">'.
                '<div class="date">'.userdate($post->modified, $strftimerecent).'</div>'.
@@ -2547,7 +2547,7 @@ function forum_make_mail_post($course, $forum, $discussion, $post, $userfrom, $u
     $options = new object();
     $options->para = true;
     $formattedtext = format_text(trusttext_strip($post->message), $post->format, $options, $course->id);
-    $anonpicture = '<img alt="' . $CFG->anonymous_name . '" src="' . $CFG->themewww . '/' . current_theme() . '/pix/anonymous.png' . '"/>';
+    $anonpicture = '<img alt="' . $CFG->forum_anonymousname . '" src="' . $CFG->themewww . '/' . current_theme() . '/pix/anonymous.png' . '"/>';
 
     $output = '<table border="0" cellpadding="3" cellspacing="0" class="forumpost">';
 
@@ -2564,7 +2564,7 @@ function forum_make_mail_post($course, $forum, $discussion, $post, $userfrom, $u
 
     $fullname = fullname($userfrom, $viewfullnames);
     $by = new object();
-    $by->name = $post->anonymous ? $CFG->anonymous_name : '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$userfrom->id.'&amp;course='.$course->id.'">'.$fullname.'</a>';
+    $by->name = $post->anonymous ? $CFG->forum_anonymousname : '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$userfrom->id.'&amp;course='.$course->id.'">'.$fullname.'</a>';
     $by->date = userdate($post->modified, '', $userto->timezone);
     $output .= '<div class="author">'.get_string('bynameondate', 'forum', $by).'</div>';
 
@@ -2753,7 +2753,7 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa
     $postuser->lastname  = $post->lastname;
     $postuser->imagealt  = $post->imagealt;
     $postuser->picture   = $post->picture;
-    $anonpicture         = '<img alt="' . $CFG->anonymous_name . '" src="' . $CFG->themewww . '/' . current_theme() . '/pix/anonymous.png' . '"/>';
+    $anonpicture         = '<img alt="' . $CFG->forum_anonymousname . '" src="' . $CFG->themewww . '/' . current_theme() . '/pix/anonymous.png' . '"/>';
 
     echo '<tr class="header"><td class="picture left">';
     $post->anonymous ? print($anonpicture) : print_user_picture($postuser, $course->id);
@@ -2776,7 +2776,7 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa
     $by = new object();
 
     if ($post->anonymous) {
-       $by->name = $CFG->anonymous_name;
+       $by->name = $CFG->forum_anonymousname;
     } else {
        $by->name = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.
             $post->userid.'&amp;course='.$course->id.'">'.$fullname.'</a>';
@@ -3053,7 +3053,7 @@ function forum_print_discussion_header(&$post, $forum, $group=-1, $datestring=""
     $postuser->lastname = $post->lastname;
     $postuser->imagealt = $post->imagealt;
     $postuser->picture = $post->picture;
-    $anonpicture = '<img alt="' . $CFG->anonymous_name . '" src="' . $CFG->themewww . '/' . current_theme() . '/pix/anonymous.png' . '"/>';
+    $anonpicture = '<img alt="' . $CFG->forum_anonymousname . '" src="' . $CFG->themewww . '/' . current_theme() . '/pix/anonymous.png' . '"/>';
 
     echo '<td class="picture">';
     $post->anonymous ? print($anonpicture) : print_user_picture($postuser, $forum->course);
@@ -3064,7 +3064,7 @@ function forum_print_discussion_header(&$post, $forum, $group=-1, $datestring=""
     echo '<td class="author">';
 
     if ($post->anonymous) {
-        echo $CFG->anonymous_name;
+        echo $CFG->forum_anonymousname;
     } else {
         echo '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$post->userid.'&amp;course='.$forum->course.'">'.$fullname.'</a>';
     }
@@ -3125,9 +3125,9 @@ function forum_print_discussion_header(&$post, $forum, $group=-1, $datestring=""
     $usermodified->id        = $post->usermodified;
     $usermodified->firstname = $post->umfirstname;
     $usermodified->lastname  = $post->umlastname;
-    $lastpost = get_record('forum_posts', 'id', $post->lastpostid);
+    $lastpost = (empty($post->lastpostid)) ? $post : get_record('forum_posts', 'id', $post->lastpostid);
     if($lastpost->anonymous) {
-        echo $CFG->anonymous_name . '<br/>';
+        echo $CFG->forum_anonymousname . '<br/>';
     } else {
         echo '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$post->usermodified.'&amp;course='.$forum->course.'">'.
              fullname($usermodified).'</a><br/>';
@@ -4997,7 +4997,7 @@ function forum_print_posts_threaded($course, &$cm, $forum, $discussion, $parent,
                 $by = new object();
 
                 if($post->anonymous) {
-                    $by->name = $CFG->anonymous_name;
+                    $by->name = $CFG->forum_anonymousname;
                 } else {
                     $by->name = fullname($post, $canviewfullnames);
                 }
@@ -5199,7 +5199,7 @@ function forum_print_recent_mod_activity($activity, $courseid, $detail, $modname
 
     echo "<tr><td class=\"userpicture\" valign=\"top\">";
     if($activity->user->anonymous) {
-        echo '<img alt="' . $CFG->anonymous_name . '" src="' . $CFG->themewww . '/' . current_theme() . '/pix/anonymous.png' . '"/>';
+        echo '<img alt="' . $CFG->forum_anonymousname . '" src="' . $CFG->themewww . '/' . current_theme() . '/pix/anonymous.png' . '"/>';
     } else {
         print_user_picture($activity->user, $courseid);
     }
@@ -5216,7 +5216,7 @@ function forum_print_recent_mod_activity($activity, $courseid, $detail, $modname
     echo '</div>';
 
     echo '<div class="user">';
-    $fullname = $activity->user->anonymous ? $CFG->anonymous_name : fullname($activity->user, $viewfullnames);
+    $fullname = $activity->user->anonymous ? $CFG->forum_anonymousname : fullname($activity->user, $viewfullnames);
     echo "<a href=\"$CFG->wwwroot/user/view.php?id={$activity->user->id}&amp;course=$courseid\">"
          ."{$fullname}</a> - ".userdate($activity->timestamp);
     echo '</div>';
diff --git a/mod/forum/search.php b/mod/forum/search.php
index 3d8d6a3..ddfe5cb 100644
--- a/mod/forum/search.php
+++ b/mod/forum/search.php
@@ -114,6 +114,7 @@
 
 /// We need to do a search now and print results
 
+    $extrasql = preg_match('/(^| )user(id)?:/', $search) ? 'AND anonymous = 0' : '';
     $searchterms = str_replace('forumid:', 'instance:', $search);
     $searchterms = explode(' ', $searchterms);
 
@@ -124,8 +125,7 @@
     $navlinks[] = array('name' => s($search, true), 'link' => '', 'type' => 'link');
     $navigation = build_navigation($navlinks);
 
-
-    if (!$posts = forum_search_posts($searchterms, $course->id, $page*$perpage, $perpage, $totalcount)) {
+    if (!$posts = forum_search_posts($searchterms, $course->id, $page*$perpage, $perpage, $totalcount, $extrasql)) {
         print_header_simple("$strsearchresults", "", $navigation, 'search.words', "", "", "&nbsp;", navmenu($course));
         print_heading(get_string("nopostscontaining", "forum", $search));
 
diff --git a/mod/forum/settings.php b/mod/forum/settings.php
index 4d71424..afc8904 100644
--- a/mod/forum/settings.php
+++ b/mod/forum/settings.php
@@ -61,4 +61,7 @@ $settings->add(new admin_setting_configcheckbox('forum_enabletimedposts', get_st
 $settings->add(new admin_setting_configcheckbox('forum_logblocked', get_string('logblocked', 'forum'),
                    get_string('configlogblocked', 'forum'), 1));
 
+// anonymous user name
+$settings->add(new admin_setting_configtext('forum_anonymousname', get_string('anonymousname', 'forum'),
+                   get_string('configanonymousname', 'forum'), 'Anonymous', PARAM_TEXT));
 ?>
diff --git a/mod/forum/version.php b/mod/forum/version.php
index a6e8257..92c5759 100644
--- a/mod/forum/version.php
+++ b/mod/forum/version.php
@@ -5,7 +5,7 @@
 //  This fragment is called by /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2007101512;
+$module->version  = 2007101513;
 $module->requires = 2007101509;  // Requires this Moodle version
 $module->cron     = 60;
 
